We are given two sequences of words:
and
,
with
.
For every
,
, we chose one of the two words:
or
.
The chosen words are merged in order of increasing indices.
The choice consists of
steps.
In each step we decide to take the
-th word from the first or from the second sequence of words.
More formally: the choice is a sequence of length
whose elements are numbers
and
.
It is possible that different choices lead to the same word.
We say that a choice is symmetrical if its result is a palindrome,
i.e. a word that is identical when we read it from left to right and from right to left.
Write a program that:
and two sequences of words
and
,
In the first line of the standard input there is one positive integer
.
In the following
lines there are written consecutive words of the sequence
— one word in one line.
In the following
lines there are written (in the similar way) consecutive words of the sequence
.
Each word consists solely of small letters of the English alphabet (from a to z).
The total length of all words is from the range
.
In the standard output there should be written one non-negative integer — the number of symmetrical choices.
For the input data:
5 ab a a ab a a baaaa a a ba
the correct result is:
12
Task author: Wojciech Rytter.
In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.